const Service = require('../../../core/service/ApiService');

class UserService extends Service {

    //首页轮播
    async getCarouselimg() {
        return this.service.miniapp.user.dao.getCarouselimg();
    }

    //获取我的设备
    async getDevice(id) {
        return this.service.miniapp.user.dao.getDevice(id);
    }

    //获取个人信息
    async getInfo(open_id) {
        return this.service.miniapp.user.dao.getInfo(open_id);
    }



    //绑定
    async bind(info) {
        const dao = this.service.miniapp.user.dao;
        const infoFromDB = await dao.getInfoFromDB(info.user_number,info.type);
        if(!infoFromDB)
            throw new this.error.BusinessError('不存在该用户');
        info.ctime = this.helper.YMDhms(new Date());
        info.credit_score = 10;
        info.status = this.constant.USER_STATUS.ENABLE;
        return this.service.miniapp.user.dao.bind(info);

    }

    //搜索
    async search(belong_number,name) {
        return this.service.miniapp.user.dao.search(belong_number,name);
    }

    async getall(belong_number) {
        return this.service.miniapp.user.dao.getall(belong_number);
    }

    //用户更改个人信息
    async changeInfo(info) {
        return this.service.miniapp.user.dao.changeInfo(info);
    }
}

module.exports = UserService;
